package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.PageReservationDto;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IMemberReservationService;
import com.zzyl.nursing.vo.TimeSlotCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member/reservation")
@Api(tags = "老人家属预约相关接口")
@Slf4j
public class MemberReservationController {
    @Autowired
    private IMemberReservationService memberReservationService;


    /**
     * 新增预约
     * @param reservationDto
     * @return
     */
    @PostMapping()
    @ApiOperation("新增预约")
    public R insertReservation(@RequestBody ReservationDto reservationDto){
        memberReservationService.insert(reservationDto);
        return R.ok();
    }

    /**
     * 分页查询预约
     * @param pageReservationDto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public R<TableDataInfo<Reservation>> reservationPage(PageReservationDto pageReservationDto){
        return R.ok(memberReservationService.pageReservation(pageReservationDto)) ;
    }

    /**
     * 查询当天取消预约次数
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public R<Integer> count(){
        Integer i=memberReservationService.countToday();
        return R.ok(i);
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public R cancel(@PathVariable Integer id){
        memberReservationService.cancel(id);
        return R.ok();
    }

    /**
     * 查询每个时间段剩余预约的次数
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public R<List<TimeSlotCountVo>> countByTime(){
        List<TimeSlotCountVo> result=memberReservationService.countByTime();
        return R.ok(result);
    }

}
